import Vue from "vue";
import App from "./App.vue";
// 三级联动组件--全局
import TypeNav from "@/components/TypeNav";
import Carsousel from "@/components/Carsousel";
import Pagination from "@/components/Pagination";
import { Button, Loading, MessageBox } from "element-ui";

//第一个参数：全局组件的名字 第二个参数：哪一个组件
Vue.component(TypeNav.name, TypeNav);
Vue.component(Carsousel.name, Carsousel);
Vue.component(Pagination.name, Pagination);
// 注册全局组件
Vue.component(Button.name, Button);
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;

// 引入路由
import router from "@/router";

//引入仓库
import store from "@/store";

//引入MockServer.js
import "@/mock/mockServe";

// 引入swiper
import "swiper/css/swiper.css";

Vue.config.productionTip = false;
//统一接收api文件夹里面的全部请求
import * as API from "@/api";
//引入懒加载
import atm from "@/assets/1.gif";

//引入插件
import VueLazyload from "vue-lazyload";

// 注册插件
Vue.use(VueLazyload, {
  //懒加载默认的图片
  loading: atm,
});

//引入表单校验插件
// import "@/plugins/validate";
import VeeValidate from "vee-validate";
Vue.use(VeeValidate);
// 中文提示信息
import zh_CN from "vee-validate/dist/locale/zh_CN";
//表单验证
VeeValidate.Validator.localize("zh_CN", {
  messages: {
    ...zh_CN.messages,
    is: (field) => `${field}必须与密码相同`, // 修改内置规则的 message，让确认密码和密码相同
  },
  attributes: {
    phone: "手机号",
    code: "验证码",
    password: "密码",
    password1: "确认密码",
    agree: "协议",
  },
});
//自定义校验规则
VeeValidate.Validator.extend("tongyi", {
  validate: (value) => {
    return value;
  },
  getMessage: (field) => field + "必须同意",
});

new Vue({
  render: (h) => h(App),
  // 全局事件总线$bus
  beforeCreate() {
    Vue.prototype.$bus = this;
    Vue.prototype.$API = API;
  },

  // 注册路由
  // 注册路由信息：组件身上有$route属性和 $router
  router,
  store,
}).$mount("#app");
